package cn.edu.jxau.test;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author Fudashi
 */
public class Main {

	public static void main(String[] args) {

		System.out.println(foo("google"));
	}

	public static String foo(String str) {

		if (Objects.requireNonNull(str, "参数str不能为null").length() == 0) {
			throw new IllegalArgumentException("参数str是空串");
		}
		final int ASCII_LEN = 256;
		boolean[] flag = new boolean[ASCII_LEN]; // 可优化为bitset
		StringBuilder result = new StringBuilder();
		for (int i = 0, end = str.length(); i < end; i++) {
			char ch = str.charAt(i);
			if (!flag[ch]) {
				result.append(ch);
				flag[ch] = true;
			}
		}
		return result.toString();
	}
}
